<!DOCTYPE html >
<html>
<head>
    <link rel="stylesheet" href="demos.css" type="text/css" media="screen" />

    <script src="../libraries/RGraph.svg.common.core.js" ></script>
    <script src="../libraries/RGraph.svg.common.tooltips.js" ></script>
    <script src="../libraries/RGraph.svg.common.csv.js" ></script>
    <script src="../libraries/RGraph.svg.bar.js" ></script>
    

    <title>RGraph demo: A thin grouped Bar chart</title>
    
    <meta name="robots" content="noindex,nofollow" />
    <meta name="description" content="A thin grouped Bar chart thats animated with margins" />
</head>
<body>



    <h1>A thin grouped Bar chart</h1>

    
    <div style="width: 950px; height: 350px; display: inline-block" id="chart-container"></div>



        <div id="fb-root"></div>
    <script>
        function loadFB (d)
        {
            var js, fjs = document.getElementsByTagName('script')[0];
            if (document.getElementById('facebook-jssdk')) {
                return;
            }
            
            js     = document.createElement('script');
            js.id  = 'facebook-jssdk';
            js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.8";
            
            fjs.parentNode.insertBefore(js, fjs);
        }
        
        
        setTimeout(loadFB, 1500);
    </script>
    
    <style>
        div#sharePopup {
            display: inline-block;
            color: white;
            z-index: 2;
            min-width: 575px;
            height: 40px;
            margin-left: 200px;
            margin-top: 20px;
            margin-bottom: 20px;
            box-shadow: 1px -1px 2px #aaa;
            background-color: rgba(0,0,0,0.75);
            text-align: center;
            font-weight: bold;
            border-radius: 10px;
        }
    
        div#sharePopup span#label {
            position: relative;
            top: 5px;
        }
        
        div#sharePopup div.fb-like {
            text-align: center;
            display: inline-block;
            position: relative;
            top: 4px;
        }
    </style>
    
    <div id="sharePopup">
        <span id="label">If you like RGraph please share it:</span>
        <span style="display: inline-block; min-width: 225px">
            <div class="fb-like" data-href="https://www.rgraph.net" data-layout="button_count" data-action="like" data-show-faces="false" data-share="true"></div>
            <a href="javascript: null" onclick="window.open('http://www.twitter.com/share?url=https://www.rgraph.net&text=HTML5%20charts%20for%20the%20web%20with%20@_RGraph%20', 'twitter-sharer-window', 'top=50,left=50,width=700,height=300')"><img src="/images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Q3,-1.7\n`05 Q4,-1.6\n`06 Q1,-2.1\n`06 Q2,-1.4\n`06 Q3,-2.8\n`07 Q1,-2.6\n`07 Q2,-1.5\n`07 Q3,-3.1\n`07 Q4,-2.5\n`08 Q1,-3.2\n`08 Q2,-3.9\n`08 Q3,-3.1\n`08 Q4,-3.9\n`09 Q1,-4.6\n`09 Q2,-3.9\n`09 Q3,-1.5\n`09 Q4,-1.9\n`10 Q1,-2.5\n`10 Q2,-2.1\n`10 Q3,-3.5\n`10 Q4,-2.8\n`11 Q1,-1\n`11 Q2,-0.2\n`11 Q3,-3\n`11 Q4,-2.9\n`12 Q1,-2.8\n`12 Q2,-4.1\n`12 Q3,-3.5\n`12 Q4,-4.3\n`13 Q1,-3.7\n`13 Q2,-3.2\n`13 Q3,-4.7\n`13 Q4,-6\n`14 Q1,-4.7\n`14 Q2,-3.9\n`14 Q3,-4.6\n`14 Q4,-5.4\n`15 Q1,-5.4\n`15 Q2,-4.7\n`15 Q3,-4.4\n`15 Q4,-7\n`16 Q1,-5.7\n`16 Q2,-5.9"

        new RGraph.CSV('str:' + csv, function (csv)
        {
            var labels   = csv.getCol(0),
                data     = csv.getCol(1),
                colors   = [],
                tooltips = [];

            data.forEach(function (v,k,arr)
            {
                colors[k] = v > 0 ? '#7CB5EC' : '#B03060';
            });
            
            var crlf = false;

            labels.forEach(function (v,k,arr)
            {
                tooltips[k] = '<b>{2}</b><br /><br />Current account deficit: <b>{1}</b>'.format(
                    data[k],
                    labels[k]
                );

                if (k % 8 !== 0) {
                    labels[k] = '';
                }
            });

            new RGraph.SVG.Bar({
                id: 'chart-container',
                data: data,
                options: {
                    yaxis:false,
                    ylabelsOffsetx: -10,
                    yaxisMin: -8,
                    yaxisMax: 2,
                    xaxis: false,
                    xaxisLabels: labels,
                    xaxisLabelsOffsety: 10,

                    tooltips: tooltips,
                    tooltipsEvent: 'mouseover',
                    tooltipsEffect: 'none',

                    textSize: 9,
                    textColor: 'gray',

                    title: 'Britain\'s current account deficit is bigger than at the height of the Lawson boom',
                    titleSize: 12,
                    titleBold: true,

                    backgroundGridVlines: false,
                    backgroundGridBorder: false,

                    gutterLeft: 50,
                    gutterBottom: 50,

                    colors: colors,
                    colorsSequential: true,

                    hmargin: 2
                }
            }).on('tooltip', function (obj)
            {
                var tooltip = RGraph.SVG.REG.get('tooltip');
                var index   = tooltip.__index__;

                if (data[index] > 0) {
                    tooltip.style.borderColor = 'blue';
                }
            }).grow({frames: 60});



            RGraph.SVG.tooltips.style.textAlign       = 'left';
            RGraph.SVG.tooltips.style.border          = '1px solid red';
            RGraph.SVG.tooltips.style.backgroundColor = 'white';
            RGraph.SVG.tooltips.style.padding         = '10px';
        });
    </script>



    <p></p>

    This goes in the documents header:
    <pre class="code">
&lt;script src="RGraph.common.core.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.common.csv.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.common.tooltips.js"&gt;&lt;/script&gt;
&lt;script src="RGraph.bar.js"&gt;&lt;/script&gt;
</pre>
    
    Put this where you want the chart to show up:
    <pre class="code">
&lt;div style="width: 950px; height: 350px; display: inline-block" id="chart-container"&gt;&lt;/div&gt;
</pre>

    This is the code that generates the chart:
    <pre class="code">
&lt;script&gt;
    csv = "`87 Q1,-0.1\n`87 Q2,-1.6\n`87 Q3,-1.8\n`87 Q4,-3\n`88 Q1,-3.3\n`88 Q2,-3.3\n`88 Q3,-3.3\n`88 Q4,-5.1\n`89 Q1,-4.2\n`89 Q2,-4.6\n`89 Q3,-4.9\n`89 Q4,-3.8\n`90 Q1,-4.3\n`90 Q2,-4.1\n`90 Q3,-2.4\n`90 Q4,-2.5\n`91 Q1,-1.8\n`91 Q2,-1\n`91 Q3,-1.5\n`91 Q4,-1.1\n`92 Q1,-1.3\n`92 Q2,-1.7\n`92 Q3,-1.9\n`92 Q4,-1.6\n`93 Q1,-1.3\n`93 Q2,-1.8\n`93 Q3,-1.3\n`93 Q4,-1.2\n`94 Q1,-0.5\n`94 Q2,-0.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\n`14 Q4,-5.4\n`15 Q1,-5.4\n`15 Q2,-4.7\n`15 Q3,-4.4\n`15 Q4,-7\n`16 Q1,-5.7\n`16 Q2,-5.9"

    new RGraph.CSV('str:' + csv, function (csv)
    {
        var labels   = csv.getCol(0),
            data     = csv.getCol(1),
            colors   = [],
            tooltips = [];

        data.forEach(function (v,k,arr)
        {
            colors[k] = v > 0 ? '#7CB5EC' : '#B03060';
        });
        
        var crlf = false;

        labels.forEach(function (v,k,arr)
        {
            tooltips[k] = '<b>{2}</b><br /><br />Current account deficit: <b>{1}</b>'.format(
                data[k],
                labels[k]
            );

            if (k % 8 !== 0) {
                labels[k] = '';
            }
        });

        new RGraph.SVG.Bar({
            id: 'chart-container',
            data: data,
            options: {
                yaxis:false,
                ylabelsOffsetx: -10,
                yaxisMin: -8,
                yaxisMax: 2,
                xaxis: false,
                xaxisLabels: labels,
                xaxisLabelsOffsety: 10,

                tooltips: tooltips,
                tooltipsEvent: 'mouseover',
                tooltipsEffect: 'none',

                textSize: 9,
                textColor: 'gray',

                title: 'Britain\'s current account deficit is bigger than at the height of the Lawson boom',
                titleSize: 12,
                titleBold: true,

                backgroundGridVlines: false,
                backgroundGridBorder: false,

                gutterLeft: 50,
                gutterBottom: 50,

                colors: colors,
                colorsSequential: true,

                hmargin: 2
            }
        }).on('tooltip', function (obj)
        {
            var tooltip = RGraph.SVG.REG.get('tooltip');
            var index   = tooltip.__index__;

            if (data[index] > 0) {
                tooltip.style.borderColor = 'blue';
            }
        }).grow({frames: 60});



        RGraph.SVG.tooltips.style.textAlign       = 'left';
        RGraph.SVG.tooltips.style.border          = '1px solid red';
        RGraph.SVG.tooltips.style.backgroundColor = 'white';
        RGraph.SVG.tooltips.style.padding         = '10px';
    });
&lt;/script&gt;
</pre>



    
    

    <p>
        <a href="./">&laquo; Back</a>
    </p>

</body>
</html>